package com.pomr.util.communication.cx211;

import java.math.BigDecimal;
import java.util.Map;
import java.util.TreeMap;

import com.alibaba.fastjson.JSONObject;
import com.pomr.util.communication.Communication;

/**
 * 
 * 类名称： CX211Back
 * 创建人： Administrator
 * 创建时间：2018年5月7日 下午8:48:50
 * 类表述：2.1.1 单卡查询接口 回参类
 */
public class CX211Back implements Communication{
	public String getCodeName() {
		return codeName;
	}
	public void setCodeName(String codeName) {
		this.codeName = codeName;
	}
	public String getOperatorName() {
		return operatorName;
	}
	public void setOperatorName(String operatorName) {
		this.operatorName = operatorName;
	}
	public String getStatusName() {
		return statusName;
	}
	public void setStatusName(String statusName) {
		this.statusName = statusName;
	}
	public String getCardTypeName() {
		return cardTypeName;
	}
	public void setCardTypeName(String cardTypeName) {
		this.cardTypeName = cardTypeName;
	}
	public String getCardPackageName() {
		return cardPackageName;
	}
	public void setCardPackageName(String cardPackageName) {
		this.cardPackageName = cardPackageName;
	}
	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
	}
	public int getOperator() {
		return operator;
	}
	public void setOperator(int operator) {
		this.operator = operator;
	}
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public String getCardType() {
		return cardType;
	}
	public void setCardType(String cardType) {
		this.cardType = cardType;
	}
	public String getUpdateTime() {
		return updateTime;
	}
	public void setUpdateTime(String updateTime) {
		this.updateTime = updateTime;
	}
	public String getOutdata() {
		return outdata;
	}
	public void setOutdata(String outdata) {
		this.outdata = outdata;
	}
	public String getTotaldata() {
		return totaldata;
	}
	public void setTotaldata(String totaldata) {
		this.totaldata = totaldata;
	}
	public String getSurplusdata() {
		return surplusdata;
	}
	public void setSurplusdata(String surplusdata) {
		this.surplusdata = surplusdata;
	}
	public String getMsisdn() {
		return msisdn;
	}
	public void setMsisdn(String msisdn) {
		this.msisdn = msisdn;
	}
	public String getImsi() {
		return imsi;
	}
	public void setImsi(String imsi) {
		this.imsi = imsi;
	}
	public String getIccid() {
		return iccid;
	}
	public void setIccid(String iccid) {
		this.iccid = iccid;
	}
	public String getAccountName() {
		return accountName;
	}
	public void setAccountName(String accountName) {
		this.accountName = accountName;
	}
	public String getActivityTime() {
		return activityTime;
	}
	public void setActivityTime(String activityTime) {
		this.activityTime = activityTime;
	}
	public String getCardPackage() {
		return cardPackage;
	}
	public void setCardPackage(String cardPackage) {
		this.cardPackage = cardPackage;
	}
	public String getExpirationTime() {
		return expirationTime;
	}
	public void setExpirationTime(String expirationTime) {
		this.expirationTime = expirationTime;
	}
	public String getFirstActivityTime() {
		return firstActivityTime;
	}
	public void setFirstActivityTime(String firstActivityTime) {
		this.firstActivityTime = firstActivityTime;
	}
	public String getPackageCode() {
		return packageCode;
	}
	public void setPackageCode(String packageCode) {
		this.packageCode = packageCode;
	}
	public String getFlowExpriationTime() {
		return flowExpriationTime;
	}
	public void setFlowExpriationTime(String flowExpriationTime) {
		this.flowExpriationTime = flowExpriationTime;
	}
	private int code;//0：正常 1：appid、secret、sign有误 2：imsi、iccid、msisdn有误 9999：意外错误
	private String codeName;
	private int operator;//1:移动 2：联通 3：电信
	private String operatorName;
	private int status;//1:激活 2：可激活 3：测试 4：停用 5：作废
	private String statusName;
	private String cardType;//当前卡片规格
	private String cardTypeName;
	private String updateTime;//更新时间
	private String outdata;//已用流量
	private String totaldata;//总流量
	private String surplusdata;//剩余流量-计算得出
	private String msisdn;//业务号码
	private String imsi;//IMSI号码
	private String iccid;//智能号码
	private String accountName;//所属账号
	private String activityTime;//主套餐激活时间
	private String cardPackage;//主套餐名称
	private String cardPackageName;
	private String expirationTime;//主套餐到期时间
	private String firstActivityTime;//卡片激活时间
	private String packageCode;//主套餐编码
	private String flowExpriationTime;//叠加包到期时间（优先级最高的）
	
	public static Object fromJson(String jsonStr) {
//		jsonStr = "{"+
//"'accountName': '18923704401',"+
//"'activityTime': '2017-05-12',"+
//"'cardPackage':"+
//"'%E8%81%94%E9%80%9A_1000M%2F%E6%9C%88_%E5%8C%85%E5%B9%B4',"+
//"'cardType': '%E7%BA%AFmicro',"+
//"'code': 0,"+
//"'expirationTime': '2018-04-26',"+
//"'firstActivityTime': '2017-05-12',"+
//"'flowExpriationTime': '2018-06-26',"+
//"'iccid': '89860616090048928111',"+
//"'imsi': '460069059003141',"+
//"'msisdn': '861064699433340',"+
//"'operator': 2,"+
//"'outdata': 314.09,"+
//"'packageCode': 4565,"+
//"'status': 1,"+
//"'totaldata': 1400,"+
//"'updateTime': '2017-09-18 17:47:38'"+
//"}";
		// TODO Auto-generated method stub
		CX211Back back = (CX211Back)JSONObject.parseObject(jsonStr, CX211Back.class);
		//查询状态
		if(back.getCode() == 0){
			back.setCodeName("查询正常");
		}else if(back.getCode() == 1){
			back.setCodeName("appid、secret、sign有误");
		}else if(back.getCode() == 2){
			back.setCodeName("imsi、iccid、msisdn有误");
		}else if(back.getCode() == 9999){
			back.setCodeName("意外错误");
		}
		
		if(back.getOperator() == 1){
			back.setOperatorName("移动");
		}else if(back.getOperator() == 2){
			back.setOperatorName("联通");
		}else if(back.getOperator() == 3){
			back.setOperatorName("电信");
		}
		
		//卡片状态
		if(back.getStatus() == 1){
			back.setStatusName("激活");
		}else if(back.getStatus() == 2){
			back.setStatusName("可激活");
		}else if(back.getStatus() == 3){
			back.setStatusName("测试");
		}else if(back.getStatus() == 4){
			back.setStatusName("停用");
		}else if(back.getStatus() == 4){
			back.setStatusName("作废");
		}
		//剩余流量
		if(back.getTotaldata() == null || back.getTotaldata().trim().equals("")){
			back.setSurplusdata("0");
		}
		else if(back.getTotaldata() == null || back.getTotaldata().trim().equals("")){
			BigDecimal b1 = new BigDecimal(back.getTotaldata());  
			BigDecimal b2 = new BigDecimal(0);  
			back.setSurplusdata(b1.subtract(b2).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
		}else{
			BigDecimal b1 = new BigDecimal(back.getTotaldata());  
			BigDecimal b2 = new BigDecimal(back.getOutdata()); 
			back.setSurplusdata(b1.subtract(b2).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
		}
		//TODO 当前卡片规格 主套餐名称需要解码 
		
		return back;
	}

}
